package weiy.top.modules.spu.service.impl;

import weiy.top.modules.spu.entity.PmsSpuImages;
import weiy.top.modules.spu.mapper.PmsSpuImagesMapper;
import weiy.top.modules.spu.service.IPmsSpuImagesService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: pms_spu_images
 * @Author: weihancheng
 * @Date: 2021-11-24
 * @Version: V1.0
 */
@Service
public class PmsSpuImagesServiceImpl extends ServiceImpl<PmsSpuImagesMapper, PmsSpuImages> implements IPmsSpuImagesService {

    @Override
    public void saveImages(String id, List<String> images) {
        if (images != null && images.size() > 0) {
            List<PmsSpuImages> collect = images.stream().map(image -> {
                PmsSpuImages spuImagesEntity = new PmsSpuImages();
                spuImagesEntity.setSpuId(id);
                spuImagesEntity.setImgUrl(image);
                return spuImagesEntity;
            }).collect(Collectors.toList());

            this.saveBatch(collect);
        }
    }
}
